package com.dalongxin.work.data;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 费用报销Bean
 */
public class Fee implements Serializable {

    private int id;
    private int companyId;
    private String companyName;
    private int departmentId;
    private String departmentName;
    private String fillDate;
    private String upperCaseFee;
    private String remark;
    private List<String> imageUrl;
    private int approveId1;
    private String approveName1;
    private int approveId2;
    private String approveName2;
    private int status;
    private int createId;
    private String createName;
    private String createTime;
    private List<FeeDetail> feeDetailList;

    /**
     * 费用报销的事由
     */
    public static class FeeDetail implements Serializable {
        private String reason;
        private double fee;

        public String getReason() {
            return reason;
        }

        public void setReason(String reason) {
            this.reason = reason;
        }

        public double getFee() {
            return fee;
        }

        public void setFee(double fee) {
            this.fee = fee;
        }

        public static FeeDetail parseFromJson(JSONObject jsonObject) {
            FeeDetail feeDetail = new FeeDetail();
            feeDetail.reason = jsonObject.optString("reason");
            feeDetail.fee = jsonObject.optDouble("fee");
            return feeDetail;
        }

        public static List<FeeDetail> parseFromJsonList(JSONArray jsonArray) {
            List<FeeDetail> list = new ArrayList<>();
            if(jsonArray != null && jsonArray.length() > 0) {
                for(int i=0;i<jsonArray.length();i++) {
                    FeeDetail item = parseFromJson(jsonArray.optJSONObject(i));
                    if(item != null)list.add(item);
                }
            }
            return list;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public int getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(int departmentId) {
        this.departmentId = departmentId;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public String getFillDate() {
        return fillDate;
    }

    public void setFillDate(String fillDate) {
        this.fillDate = fillDate;
    }

    public String getUpperCaseFee() {
        return upperCaseFee;
    }

    public void setUpperCaseFee(String upperCaseFee) {
        this.upperCaseFee = upperCaseFee;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<String> getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(List<String> imageUrl) {
        this.imageUrl = imageUrl;
    }

    public int getApproveId1() {
        return approveId1;
    }

    public void setApproveId1(int approveId1) {
        this.approveId1 = approveId1;
    }

    public String getApproveName1() {
        return approveName1;
    }

    public void setApproveName1(String approveName1) {
        this.approveName1 = approveName1;
    }

    public int getApproveId2() {
        return approveId2;
    }

    public void setApproveId2(int approveId2) {
        this.approveId2 = approveId2;
    }

    public String getApproveName2() {
        return approveName2;
    }

    public void setApproveName2(String approveName2) {
        this.approveName2 = approveName2;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getCreateId() {
        return createId;
    }

    public void setCreateId(int createId) {
        this.createId = createId;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public List<FeeDetail> getFeeDetailList() {
        return feeDetailList;
    }

    public void setFeeDetailList(List<FeeDetail> feeDetailList) {
        this.feeDetailList = feeDetailList;
    }

    public static Fee parseFromJson(JSONObject jsonObject) {
        Fee buy = new Fee();
        buy.id = jsonObject.optInt("id");
        buy.companyId = jsonObject.optInt("companyId");
        buy.companyName = jsonObject.optString("companyName");
        buy.departmentId = jsonObject.optInt("departmentId");
        buy.departmentName = jsonObject.optString("departmentName");
        buy.fillDate = jsonObject.optString("fillDate");
        buy.upperCaseFee = jsonObject.optString("upperCaseFee");
        buy.remark = jsonObject.optString("remark");
        buy.imageUrl = new ArrayList<>();
        String str = jsonObject.optString("imageUrl");
        if(str != null) {
            if(str.contains(",")) {
                String[] ss = str.split(",");
                for(String s : ss) {
                    buy.imageUrl.add(s);
                }
            }else {
                buy.imageUrl.add(str);
            }
        }
        buy.approveId1 = jsonObject.optInt("approveId1");
        buy.approveName1 = jsonObject.optString("approveName1");
        buy.approveId2 = jsonObject.optInt("approveId2");
        buy.approveName2 = jsonObject.optString("approveName2");
        buy.status = jsonObject.optInt("status");
        buy.createId = jsonObject.optInt("createId");
        buy.createName = jsonObject.optString("createName");
        buy.createTime = jsonObject.optString("createTime");
        buy.feeDetailList = FeeDetail.parseFromJsonList(jsonObject.optJSONArray("feeDetailList"));
        return buy;
    }

    public static List<Fee> parseFromJsonList(JSONArray jsonArray) {
        List<Fee> list = new ArrayList<>();
        if(jsonArray != null && jsonArray.length() > 0) {
            for(int i=0;i<jsonArray.length();i++) {
                Fee item = parseFromJson(jsonArray.optJSONObject(i));
                if(item != null)list.add(item);
            }
        }
        return list;
    }
}
